import 'package:flutter/cupertino.dart';

import 'LoggerUtil.dart';

var _logger = createLogger();

// 创建浮层
OverlayEntry createOverlayEntry(BuildContext context, Widget child) {
  return OverlayEntry(
    builder: (context) => child, // 这里可以自定义你想要显示的Widget
  );
}

// 显示浮层
OverlayEntry showOverlay(BuildContext context, Widget child) {
  final overlay = Overlay.of(context);
  final overlayEntry = createOverlayEntry(context, child);
  overlay.insert(overlayEntry);
  return overlayEntry;
}

// 移除浮层
void removeOverlay(OverlayEntry overlayEntry) {
  try {
    overlayEntry.remove();
  } catch(error) {
    _logger.e("close overlay error", error: error, time: DateTime.now());
  }
}